package com.edushare.common.vo;

import com.edushare.common.constants.DefaultFiles;
import com.edushare.common.vo.FileDirectories.DIRECTORY_OWNER_TYPE;
import com.edushare.common.vo.auto._Courses;
import com.edushare.common.vo.interfaces.IFileUploadable;

public class Courses extends _Courses implements IFileUploadable,
		EduShareEntity, NameComparision {
	private static final long serialVersionUID = -6853400301294770027L;

	public static final int COURSE_OFFERED 						= 10;
	public static final int COURSE_WITHDRAWN 					= 20;

	public final static int PREREQUISITE_COURSES_AND 			= 10;
	public final static int PREREQUISITE_COURSES_OR 			= 20;
	
	public static final Integer NOT_AVAILABLE 					= -1;

	public static boolean isValidCourse(Courses c) {
		return !(c == null || c.getCourseName() == null || c.getCourseName().trim().equals(""));
	}

	public Courses() {
		setLectureHours(NOT_AVAILABLE);
		setPracticalHours(NOT_AVAILABLE);
		setTutorialHours(NOT_AVAILABLE);
		setStrength(NOT_AVAILABLE);//TODO: set unlimited by default!
		setCredits(NOT_AVAILABLE);
		setStatus(COURSE_OFFERED);
	}

	/** IFileUploadable implementation starts */
	public String getUploadedFileUrl() {
		if (getImageFile() == null) {
			return DefaultFiles.getDefaultImageFileUrl(this);
		}
		return getImageFile().getFileDownloadUrl();
	}

	public DIRECTORY_OWNER_TYPE getObjectType() {
		return DIRECTORY_OWNER_TYPE.COURSES;
	}

	public int getObjectPrimaryKey() {
		return getCourseId();
	}

	public String getTitle() {
		return getCourseName();
	}
	/** IFileUploadable implementation ends */

	public String getName() {
		return getCourseName();
	}

	public int compareTo(INameComparable o) {
		return getName().compareTo(o.getName());
	}
	
	@Override
	public void setCourseCode(String s){
		super.setCourseCode(s.trim());
	}
	
	public String getCreditString(){
		if(super.getCredits() < 0)
			return "N/A";
		else
			return super.getCredits().toString();
	}
	
	public String getBriefDescString(){
		String str = "";
		if(super.getCredits() >= 0){
			str += getCreditString();
		}
		int l = getLectureHours();
		int t = getTutorialHours();
		int p = getPracticalHours();
		if(l >= 0 || t >= 0 || p >=0){
			if(super.getCredits() >= 0)
				str +=", ";
			str += (l>=0?l:"N/A")+"-"+(p>=0?p:"N/A")+"-"+(t>=0?p:"N/A");
		}
		return str;
	}
	
	@Override
	public Integer getCredits(){
		if(super.getCredits() < 0)
			return 0;
		return super.getCredits();
	}
}
